package request

import (
	"github.com/astaxie/beego/validation"
	"shop-bean/dto"
	"shop-common/utils"
)

type StoreCategoryRequest struct {
	CategoryId     uint               `json:"categoryId"`                            //分类Id
	CategoryName   string             `json:"categoryName" binding:"required"`       //分类名称 必填
	ParentId       uint               `json:"parentId"`                              //父Id
	BigAttachment  *dto.AttachmentDTO `json:"bigAttachment"`                         //分类大图
	IconAttachment *dto.AttachmentDTO `json:"iconAttachment"`                        //分类图标
	Seq            int                `json:"seq"`                                   //排序
	Status         int                `json:"status" binding:"required" default:"2"` //状态 2 正常状态 1 下线状态 必填
	Type           uint8              `json:"type" default:"1"`                      //类型ID | 类型，1 产品分类，2 附件分类
}

func (c *StoreCategoryRequest) Valid(v *validation.Validation) {
	if c.CategoryName == "" {
		v.SetError("CategoryName", "分类名称不能为空")
	} else if !utils.IntIncludes([]int{1, 2}, c.Status) {
		v.SetError("Status", "状态不合法")
	} else if !utils.UintIncludes([]uint{1, 2}, uint(c.Type)) {
		v.SetError("Type", "分类不合法")
	}
}
